package com.atgugui.eduservice.controller.front;

import com.atgugui.commonutils.Result;
import com.atgugui.eduservice.entity.EduCourse;
import com.atgugui.eduservice.entity.EduTeacher;
import com.atgugui.eduservice.service.EduCourseService;
import com.atgugui.eduservice.service.EduTeacherService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

@Api(tags = "用户讲师信息控制层")
@RestController
@RequestMapping("/eduservice/teacherfront")
@CrossOrigin
public class TeacherFrontController {

    @Autowired
    private EduTeacherService eduTeacherService;

    @Autowired
    private EduCourseService eduCourseService;

    @ApiOperation(value = "分页查询讲师信息")
    @GetMapping("/pageTeacherFront/{current}/{limit}")
    public Result pageTeacherFrontList(@PathVariable Long current, @PathVariable Long limit) {
        Page<EduTeacher> teacherPage = new Page<>(current,limit);
        HashMap<String, Object> pageMap = eduTeacherService.getTeacherFrontList(teacherPage);
        return Result.ok().data(pageMap);
    }

    @ApiOperation(value = "根据课程id查询课程和该课程的视频信息")
    @GetMapping("/getCourseAndTeacherInfoByCourseId/{teacherId}")
    public Result getCourseAndTeacherInfoByCourseId(@PathVariable String teacherId) {
        // 查询讲师信息
        EduTeacher eduTeacher = eduTeacherService.getById(teacherId);

        // 查询讲师对应的课程信息(通过讲师id查询课程信息)
        QueryWrapper<EduCourse> courseQueryWrapper = new QueryWrapper<>();
        courseQueryWrapper.eq("teacher_id",teacherId);
        List<EduCourse> eduCourseList = eduCourseService.list(courseQueryWrapper);
        return Result.ok().data("teacher",eduTeacher).data("courseList",eduCourseList);
    }
}
